﻿using System;
using FineUI;
using System.Collections.Generic;
using SDLITS.Common;
using SDLITS.Model;
using System.Data;
using System.Data.SqlClient;

namespace SDLITS.Web.Customer
{
    public partial class ExpenseReport : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txt_end.SelectedDate = DateTime.Now;
            }
        }

        protected void BindData()
        {
            DateTime? startDate = Convert.ToDateTime("1900-01-01");
            DateTime? endDate = null;
            if (!string.IsNullOrEmpty(txt_start.Text))
            {
                startDate = Convert.ToDateTime(txt_start.Text);
            }
            if (!string.IsNullOrEmpty(txt_end.Text))
            {
                endDate = Convert.ToDateTime(txt_end.Text).AddDays(1);
            }

            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@StartDate",startDate),
                    new SqlParameter("@EndDate",endDate),
                    new SqlParameter("@SPAction","GetExpenseReport")
                };
            DataSet ds = SDDbSession.Default.FromProc("TableContract").AddParameter(sp).ToDataSet();//.ToDataTable();
            if (ds != null && ds.Tables.Count > 0)
            {
                decimal rentTotalCase1, rentTotalCase2, rentTotalCase3, rentTotalCase4;
                decimal rentInCase1, rentInCase2, rentInCase3, rentInCase4;
                decimal rentOutCase1, rentOutCase2, rentOutCase3, rentOutCase4;

                decimal.TryParse(ds.Tables[0].Rows[0][0] is DBNull ? "0.00" : ds.Tables[0].Rows[0][0].ToString(),
                                  out rentTotalCase1);
                decimal.TryParse(ds.Tables[1].Rows[0][0] is DBNull ? "0.00" : ds.Tables[1].Rows[0][0].ToString(),
                                 out rentTotalCase2);
                decimal.TryParse(ds.Tables[2].Rows[0][0] is DBNull ? "0.00" : ds.Tables[2].Rows[0][0].ToString(),
                                 out rentTotalCase3);
                decimal.TryParse(ds.Tables[3].Rows[0][0] is DBNull ? "0.00" : ds.Tables[3].Rows[0][0].ToString(),
                                 out rentTotalCase4);

                decimal.TryParse(ds.Tables[4].Rows[0][0] is DBNull ? "0.00" : ds.Tables[4].Rows[0][0].ToString(),
                                 out rentInCase1);
                decimal.TryParse(ds.Tables[5].Rows[0][0] is DBNull ? "0.00" : ds.Tables[5].Rows[0][0].ToString(),
                                 out rentInCase2);
                decimal.TryParse(ds.Tables[6].Rows[0][0] is DBNull ? "0.00" : ds.Tables[6].Rows[0][0].ToString(),
                                 out rentInCase3);
                decimal.TryParse(ds.Tables[7].Rows[0][0] is DBNull ? "0.00" : ds.Tables[7].Rows[0][0].ToString(),
                                 out rentInCase4);

                decimal.TryParse(ds.Tables[8].Rows[0][0] is DBNull ? "0.00" : ds.Tables[8].Rows[0][0].ToString(),
                                 out rentOutCase1);
                decimal.TryParse(ds.Tables[9].Rows[0][0] is DBNull ? "0.00" : ds.Tables[9].Rows[0][0].ToString(),
                                 out rentOutCase2);
                decimal.TryParse(ds.Tables[10].Rows[0][0] is DBNull ? "0.00" : ds.Tables[10].Rows[0][0].ToString(),
                                 out rentOutCase3);
                decimal.TryParse(ds.Tables[11].Rows[0][0] is DBNull ? "0.00" : ds.Tables[11].Rows[0][0].ToString(),
                                 out rentOutCase4);

                txt_fzze.Text = (rentTotalCase1 + rentTotalCase2 + rentTotalCase3 + rentTotalCase4).ToString() + "元";
                txt_fzys.Text = (rentInCase1 + rentInCase2 + rentInCase3 + rentInCase4).ToString() + "元";
                txt_fzws.Text = (rentOutCase1 + rentOutCase2 + rentOutCase3 + rentOutCase4).ToString() + "元";

                decimal elecTotal, elecIn, elecOut;

                decimal.TryParse(ds.Tables[12].Rows[0][0] is DBNull ? "0.00" : ds.Tables[12].Rows[0][0].ToString(),
                                 out elecTotal);
                decimal.TryParse(ds.Tables[13].Rows[0][0] is DBNull ? "0.00" : ds.Tables[13].Rows[0][0].ToString(),
                                 out elecIn);
                decimal.TryParse(ds.Tables[14].Rows[0][0] is DBNull ? "0.00" : ds.Tables[14].Rows[0][0].ToString(),
                                 out elecOut);

                txt_dfze.Text = elecTotal.ToString() + "元";
                txt_dfys.Text = elecIn.ToString() + "元";
                txt_dfws.Text = elecOut.ToString() + "元";




            }
        }

        protected void btn_jf_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}